package org.zxp.javacheck.shallowdeepcopy.deep.deep3;

import com.alibaba.fastjson.JSON;
import org.zxp.javacheck.shallowdeepcopy.deep.Student;
import org.zxp.javacheck.shallowdeepcopy.deep.Subject;

/**
 * @program: effectiveJava
 * @description: json序列化反序列化实现的深拷贝
 * @author: X-Pacific zhang
 * @create: 2019-12-01 09:36
 **/
public class JsonDeep {
    public static void main(String[] args){
        Subject subject = new Subject("yuwen");
        Student studentA = new Student();
        studentA.setSubject(subject);
        studentA.setName("Lynn");
        studentA.setAge(20);

        String tmpStr = JSON.toJSONString(studentA);
        Student studentB = JSON.parseObject(tmpStr, Student.class);
        studentB.getSubject().setName("lishi");

        //subject对象不是同一个的对象
        System.out.println("studentA:" + studentA.toString());
        System.out.println("studentB:" + studentB.toString());
    }
}
